import { Component, ResolutionPolicy, _decorator, view } from "cc";
import GlobalVar from "../../GlobalVar";
/**
 * 屏幕适配策略，目的是适配所有的设备，尽可能一套UI适配所有的情况
 */
const {ccclass,property}=_decorator
@ccclass
export default class ResolutionAdapter extends Component{
    protected onLoad(): void {
        const gVar=GlobalVar.getInstance()
        //if(screen.orientation.angle==0){
        if(screen.width<screen.height){
            const ratio=screen.width/screen.height
            //竖屏
            if(ratio<0.6){
                view.setDesignResolutionSize(750,1334,ResolutionPolicy.FIXED_WIDTH)
            }else{
                view.setDesignResolutionSize(800,1280,ResolutionPolicy.FIXED_WIDTH)
            }
            console.log('适配宽度')
            gVar.resolutionPolicy=ResolutionPolicy.FIXED_WIDTH
            //console.log(screen.orientation.type)
        }else{
            const ratio=screen.width/screen.height
            //横屏
            if(ratio>1.6){
                view.setDesignResolutionSize(1334,750,ResolutionPolicy.FIXED_HEIGHT)
            }else{
                view.setDesignResolutionSize(1280,800,ResolutionPolicy.FIXED_HEIGHT)
            }
            console.log('适配高度')
            gVar.resolutionPolicy=ResolutionPolicy.FIXED_HEIGHT
            //console.log(screen.orientation.type)
        }
        console.log(screen.orientation.type)
        console.log(view.getVisibleSize())
    }
}